﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Model;
using DataLayer;

namespace BusinnessLogic
{
    public class Sprintview
    {
        public List<ChartPoint> CreateChartArray(int sprintid)
        {
            DataLayer.dlburndownchart dlburndatamaker = new DataLayer.dlburndownchart();
            DataSet dts = new DataSet();
            dts = dlburndatamaker.myburndownchart(sprintid);

            List<ChartPoint> mylist = new List<ChartPoint>();

            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                ChartPoint chrtpt = new ChartPoint();
                chrtpt.Ywaarde = int.Parse(dts.Tables[0].Rows[i]["YValue"].ToString());
                chrtpt.Datum = (DateTime)dts.Tables[0].Rows[i]["TimeStamp"];
                chrtpt.Ewl = int.Parse(dts.Tables[0].Rows[i]["EWL"].ToString());
                chrtpt.Rwl = int.Parse(dts.Tables[0].Rows[i]["RWL"].ToString());
                mylist.Add(chrtpt);
            }

            return mylist;

        }


        public List<UserStory> PopulateUserstoryList(int sprintid)
        {
            DataLayer.dluserstorylist DLuserstoryfiller = new DataLayer.dluserstorylist();
            DataSet dts = DLuserstoryfiller.UserStoryList(sprintid);

            List<UserStory> userstorylist = new List<UserStory>();

            
            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                int userstoryid = int.Parse(dts.Tables[0].Rows[i]["UserStoryId"].ToString());
                string userstorytitel = dts.Tables[0].Rows[i]["Titel"].ToString();
                string status = dts.Tables[0].Rows[i]["Status"].ToString();
                string description = dts.Tables[0].Rows[i]["Description"].ToString();
                int estimate = 0;
                int.TryParse(dts.Tables[0].Rows[i]["EstimatedWorkload"].ToString(), out estimate);
                int real = 0;
                if (dts.Tables[0].Rows[i]["RealWorkload"].ToString() != "")
                {
                    real = int.Parse(dts.Tables[0].Rows[i]["RealWorkload"].ToString());
                }
                int weight = int.Parse(dts.Tables[0].Rows[i]["BusinessWeight"].ToString());
                //int sprintid = int.Parse(dts.Tables[0].Rows[i]["SprintID"].ToString());

                UserStory eenuserstory = new UserStory(userstoryid, userstorytitel, description, status, estimate, real, weight,sprintid);
                userstorylist.Add(eenuserstory);

            }
            return userstorylist;
        }

        public List<Tasks> PopulateTasksList(int prodid)
        {
            DataLayer.dlTasks DLTasksfiller = new DataLayer.dlTasks();
            DataSet dts = DLTasksfiller.TasksList(prodid);

            List<Tasks> Taskslist = new List<Tasks>();


            for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
            {
                int taskid = int.Parse(dts.Tables[0].Rows[i]["taskId"].ToString());
                string taskstitel = dts.Tables[0].Rows[i]["Titel"].ToString();
                string status = dts.Tables[0].Rows[i]["Status"].ToString();
                string description = dts.Tables[0].Rows[i]["Description"].ToString();
                int userstoryid = int.Parse(dts.Tables[0].Rows[i]["UserstoryId"].ToString());
                int estimate = int.Parse(dts.Tables[0].Rows[i]["EstimatedWorkload"].ToString());
                int real = 0;
                if (dts.Tables[0].Rows[i]["RealWorkload"].ToString() != "")
                {
                    real = int.Parse(dts.Tables[0].Rows[i]["RealWorkload"].ToString());
                }
                int userid = int.Parse(dts.Tables[0].Rows[i]["UserId"].ToString());
                string comment = dts.Tables[0].Rows[i]["Comment"].ToString();

                Tasks eentask = new Tasks(taskid, taskstitel, comment, description, status, userstoryid, estimate, real, userid);
                
                DataSet dtts = DLTasksfiller.TasksUser(userid);
                eentask.Username = dtts.Tables[0].Rows[0]["Name"].ToString();
                eentask.Userfirstname = dtts.Tables[0].Rows[0]["FirstName"].ToString();
                Taskslist.Add(eentask);

            }
            return Taskslist;
        }
    }
}
